package com.akk.module.message;


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 短信发送工具
 *
 * @company www.lovekaka.com
 * @auther hainlc
 * @create 2017/04/28 11:10
 */
public abstract class MessageService {

    public static String getMD5(String sourceStr) throws UnsupportedEncodingException {
        String resultStr = "";
        try {
            byte[] temp = sourceStr.getBytes();
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(temp);
            // resultStr = new String(md5.digest());
            byte[] b = md5.digest();
            for (int i = 0; i < b.length; i++) {
                char[] digit = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
                        '9', 'A', 'B', 'C', 'D', 'E', 'F' };
                char[] ob = new char[2];
                ob[0] = digit[(b[i] >>> 4) & 0X0F];
                ob[1] = digit[b[i] & 0X0F];
                resultStr += new String(ob);
            }
            return resultStr;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    public abstract String sendSpecialMessage(String mobile, String content, String ext, String stime,
                              String rrid, String msgfmt) throws  UnsupportedEncodingException;

    public abstract String sendNormalMessage(String mobile, String content, String ext, String stime,
                                    String rrid,String msgfmt) throws IOException;


}
